home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / plugins / HTMLWindow.jar / horst / LayoutInfo.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-03-18  |  3.4 KB  |  150 lines

  1. package horst;
  2.  
  3. import java.awt.Rectangle;
  4. import java.util.Stack;
  5. import java.util.Vector;
  6.  
  7. public class LayoutInfo {
  8.    private Stack left = new Stack();
  9.    private Stack right = new Stack();
  10.    Vector pendingFloaters = new Vector();
  11.    int leftMargin;
  12.    int rightMargin;
  13.    int insetsRight;
  14.    int insetsLeft;
  15.    int nPageBreaks;
  16.    int pageBreakHeight = 40;
  17.    int pageHeight = 300;
  18.    int pageWidth;
  19.    Rectangle pageBreak;
  20.    boolean bPaginate;
  21.  
  22.    public LayoutInfo() {
  23.       this.pageBreak = new Rectangle(0, this.pageHeight, Integer.MAX_VALUE, this.pageBreakHeight);
  24.       this.bPaginate = false;
  25.    }
  26.  
  27.    void clear() {
  28.       this.left.removeAllElements();
  29.       this.right.removeAllElements();
  30.       this.leftMargin = 0;
  31.       this.rightMargin = 0;
  32.       this.nPageBreaks = 0;
  33.       this.pageBreak = new Rectangle(0, this.pageHeight, Integer.MAX_VALUE, this.pageBreakHeight);
  34.    }
  35.  
  36.    int clearLeftMargin() {
  37.       int yEnd;
  38.       FloatStackItem item;
  39.       for(yEnd = -1; this.left.size() > 0; yEnd = Math.max(yEnd, item.yEnd)) {
  40.          item = (FloatStackItem)this.left.pop();
  41.       }
  42.  
  43.       this.leftMargin = 0;
  44.       return yEnd;
  45.    }
  46.  
  47.    int clearMargins() {
  48.       int leftEnd = this.clearLeftMargin();
  49.       int rightEnd = this.clearRightMargin();
  50.       return Math.max(rightEnd, leftEnd);
  51.    }
  52.  
  53.    int clearRightMargin() {
  54.       int yEnd;
  55.       FloatStackItem item;
  56.       for(yEnd = -1; this.right.size() > 0; yEnd = Math.max(yEnd, item.yEnd)) {
  57.          item = (FloatStackItem)this.right.pop();
  58.       }
  59.  
  60.       this.rightMargin = 0;
  61.       return yEnd;
  62.    }
  63.  
  64.    void decreaseInsetsLeft(int amount) {
  65.       this.insetsLeft -= amount;
  66.       if (this.insetsLeft < 0) {
  67.          this.insetsLeft = 0;
  68.       }
  69.  
  70.    }
  71.  
  72.    void decreaseInsetsRight(int amount) {
  73.       this.insetsRight -= amount;
  74.       if (this.insetsRight < 0) {
  75.          this.insetsRight = 0;
  76.       }
  77.  
  78.    }
  79.  
  80.    int getLeftYEnd() {
  81.       if (this.left.size() > 0) {
  82.          FloatStackItem item = (FloatStackItem)this.left.peek();
  83.          return item.yEnd;
  84.       } else {
  85.          return -1;
  86.       }
  87.    }
  88.  
  89.    int getRightYEnd() {
  90.       if (this.right.size() > 0) {
  91.          FloatStackItem item = (FloatStackItem)this.right.peek();
  92.          return item.yEnd;
  93.       } else {
  94.          return -1;
  95.       }
  96.    }
  97.  
  98.    void increaseInsetsLeft(int amount) {
  99.       this.insetsLeft += amount;
  100.    }
  101.  
  102.    void increaseInsetsRight(int amount) {
  103.       this.insetsRight += amount;
  104.    }
  105.  
  106.    FloatStackItem popLeft() {
  107.       FloatStackItem item = null;
  108.       if (this.left.size() > 0) {
  109.          item = (FloatStackItem)this.left.pop();
  110.          this.leftMargin -= item.width;
  111.          this.leftMargin = Math.max(0, this.leftMargin);
  112.       }
  113.  
  114.       return item;
  115.    }
  116.  
  117.    FloatStackItem popRight() {
  118.       FloatStackItem item = null;
  119.       if (this.right.size() > 0) {
  120.          item = (FloatStackItem)this.right.pop();
  121.          this.rightMargin -= item.width;
  122.          this.rightMargin = Math.max(0, this.rightMargin);
  123.       }
  124.  
  125.       return item;
  126.    }
  127.  
  128.    void pushLeft(FloatStackItem item) {
  129.       this.leftMargin += item.width;
  130.       this.left.push(item);
  131.    }
  132.  
  133.    void pushRight(FloatStackItem item) {
  134.       this.rightMargin += item.width;
  135.       this.right.push(item);
  136.    }
  137.  
  138.    void setPageBreak(int y) {
  139.       if (this.bPaginate) {
  140.          int start = this.pageHeight;
  141.  
  142.          for(int end = start + this.pageBreakHeight; (y < start || y > end) && y >= start; end = start + this.pageBreakHeight) {
  143.             start = end + this.pageHeight;
  144.          }
  145.  
  146.          this.pageBreak.setBounds(0, start, Integer.MAX_VALUE, this.pageBreakHeight);
  147.       }
  148.    }
  149. }
  150.